﻿@{
    ViewBag.MainMenu = "Member";
    ViewBag.LeftMenu = "PointCommodityOrder";

    ViewBag.Title = "商城订单";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script language="javascript">

    //当前页
    var _currentPage = 1;

    $(document).ready(function ()
    {
        if (_online == false)
            return;

        loadData();

        $("[keyenter]").keypress(function (e)
        {
            if (e.keyCode == 13)
            {
                loadData();
            }
        });
    });

    function loadData(targetPage)
    {
        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        var args = new Object();
        args.Page = targetPage || 1;
        args.OrderNumber = $("#txtSearch_OrderNumber").val();
        args.MemberNickName = $("#txtSearch_MemberNickName").val();
        args.Status = $("#selectSearch_Status").val();

        $.ajax({
            url: "/Api/PointCommodity/GetPointCommodityOrderList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR)
            {
                // alert(data);

                layer.close(loadLayerIndex);

                if (data.Success)
                {
                    var resultObj = data.Data;

                    _currentPage = resultObj.Page;

                    //alert(JSON.stringify(resultObj));
                    var gettpl = document.getElementById('tableTemplate').innerHTML;
                    laytpl(gettpl).render(resultObj.ItemList, function (html)
                    {
                        document.getElementById('divTableBodyContainer').innerHTML = html;
                        fitTable();
                    });

                    laypage({
                        skin: 'yahei',
                        cont: document.getElementById('divPagingContainer'),
                        pages: resultObj.TotalPage, //总页数
                        curr: resultObj.Page, //当前页
                        groups: 7, //连续显示分页数
                        jump: function (obj, first)
                        {
                            if (!first)
                            { //点击跳页触发函数自身，并传递当前页：obj.curr
                                loadData(obj.curr);
                            }
                        }
                    });

                } else
                {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function scrollHeader()
    {
        // alert(divTableBodyContainer.scrollLeft);
        var ml = 0 - divTableBodyContainer.scrollLeft;
        document.getElementById("tableHeader").style.cssText = "margin-left:" + ml + "px;";
    }

    function fitTable()
    {
        $("#tableBody").width($("#tableHeader").width());

        $("#tableHeader tr:first").each(function (n, value)
        {
            $(this).find("td").each(function (n, value)
            {
                $("#tableBody tr:first td:eq(" + n + ")").width(value.width)
            });
        });
    }

    function showOrderDetail(id)
    {
        layer.open({
            type: 2,
            area: ['640px', '100%'], //宽高
            closeBtn: false,
            title: "",
            shift: _layerShift,
            content: 'PointCommodityOrderDetail?id=' + id
        });
    }

</script>


<script id="tableTemplate" type="text/html">

    <table id="tableBody" border="0" cellspacing="0" cellpadding="0">

        {{# for(var i = 0, len = d.length; i < len; i++){ }}
        {{# var price = accDiv(d[i].Price,100) }}
        <tr>
            <td height="35"> {{ d[i].OrderTime }}</td>
            <td ><a href="javascript:void(0)" onclick="showOrderDetail('{{ d[i].Id }}')">{{ d[i].OrderNumber }}</a></td>
            <td>{{ d[i].MemberNickName }}</td>
            <td>{{ d[i].Point }}</td>
            <td>{{ price }}</td>
            <td>
                {{# if(d[i].Status == 1){ }}
                已付款
                {{# }else if(d[i].Status == 2){ }}
                已发货
                {{# }else if(d[i].Status == 3){ }}
                已取消
                {{# }else if(d[i].Status == 4){ }}
                待付款
                {{# } }}
            </td>
            @*<td>{{# if(d[i].DealTime != null ){  var dealTime = new Date(d[i].DealTime).format("yyyy-MM-dd hh:mm:ss");}}{{ dealTime }}{{# } }}</td>*@
        </tr>
        {{# } }}

    </table>

</script>

<div style="margin-top:16px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td bgcolor="#F6F6F6">
                <div style="padding:10px;">
                    <table width="100%" border="0" cellspacing="0" cellpadding="8">
                        <tr>
                            <td width="80">订单号：</td>
                            <td width="220"> <input id="txtSearch_OrderNumber" name="txtSearch_OrderNumber" type="text" class="input_16" style="width:200px;" maxlength="30" keyenter /></td>
                            <td width="80">&nbsp;</td>
                            <td width="220">&nbsp;</td>
                            <td>&nbsp;</td>
                            <td width="100" align="right">
                                <span style=" margin-top:20px;">
                                    <input name="btnSearch" type="button" class="btn_blue" id="btnSearch" value="查询" onclick="loadData()" />
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td>会员昵称：</td>
                            <td><input id="txtSearch_MemberNickName" name="txtSearch_MemberNickName" type="text" class="input_16" style="width:200px;" maxlength="50" keyenter /></td>
                            <td>订单状态：</td>
                            <td>
                                <select id="selectSearch_Status" name="selectSearch_Status" class="input_16" style="width:200px;">
                                    <option value="0">全部</option>
                                    <option value="1">已付款</option>
                                    <option value="2">已发货</option>
                                    <option value="3">已取消</option>
                                    <option value="4">待付款</option>
                                </select>
                            </td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                    </table>

                </div>
            </td>
        </tr>
        <tr style="height:5px;background-image:url(Images/searchArea_bottom.jpg);background-repeat: repeat-x;">
            <td></td>
        </tr>
    </table>

</div>




<div style=" margin-top:20px">
    <div style="overflow:hidden; padding-left:20px;" class="tableHeader">

        <table id="tableHeader" border="0" cellspacing="0" cellpadding="0" width="830" height="47">
            <tr>
                <td width="180">下单时间</td>
                <td width="150">订单号</td>
                <td width="200">会员昵称</td>
                <td width="100">积分</td>
                <td width="100">金额</td>
                <td width="100">订单状态</td>
            </tr>
        </table>

    </div>



    <div style=" margin-top:10px">
        <!--div必须要设置height，否则滚动条出不来-->
        <div id="divTableBodyContainer" style="overflow:auto; height:100%;; padding-left:20px;" onscroll="scrollHeader()">
        </div>

    </div>

</div>
<div style="height:1px; margin-top:5px; background-color:#cccccc">

</div>

<div id="divPagingContainer" style=" margin-top:20px; margin-bottom:20px;text-align:right; ">

</div>


